import 'package:app/views/yun_markdown_text_input.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:markdown_editable_textinput/format_markdown.dart';
import 'package:markdown_editable_textinput/markdown_text_input.dart';

class DesktopMarkDownEditor extends StatefulWidget {
  const DesktopMarkDownEditor({super.key});

  @override
  State<StatefulWidget> createState() {
    return DesktopMarkDownEditorViewModel();
  }
}

class DesktopMarkDownEditorViewModel extends State<DesktopMarkDownEditor> {
  String _content = '';
  TextEditingController controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    Size windowSize = MediaQuery.of(context).size;
    return Material(
      child: Row(
        children: <Widget>[
          Container(
            width: windowSize.width / 2,
            child: YunMarkdownTextInput(
              (String value) => setState(() => _content = value),
              _content,
              label: '请输入正文内容',
              actions: MarkdownType.values,
              controller: controller,
            ),
          ),
          Container(
            width: windowSize.width / 2,
            child: Markdown(data: _content),
          )
        ],
      ),
    );
  }
}
